﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace ColdStorage.DOL
{
    [Serializable]
    public class Wall
    {
        #region Wall attributes
        public int iWallType
        {
            get { return iwallType; }
            set { iwallType = value; }
        }
        int iwallMaterials = -1;

        public int iWallMaterials
        {
            get { return iwallMaterials; }
            set { iwallMaterials = value; }
        }

        String swallName;

        public String sWallName
        {
            get { return swallName; }
            set { swallName = value; }
        }
        double dbwallOutsideExposure;

        public double dbWallOutsideExposure
        {
            get { return dbwallOutsideExposure; }
            set { dbwallOutsideExposure = value; }
        }


        double dbwallHeatTransferCoefficient;

        public double dbWallHeatTransferCoefficient
        {
            get { return dbwallHeatTransferCoefficient; }
            set { dbwallHeatTransferCoefficient = value; }
        }
        double dbwallLength;

        public double dbWallLength
        {
            get { return dbwallLength; }
            set { dbwallLength = value; }
        }
        double dbwallWidth;

        public double dbWallWidth
        {
            get { return dbwallWidth; }
            set { dbwallWidth = value; }
        }
        int iwallDirection = -1;

        public int iWallDirection
        {
            get { return iwallDirection; }
            set { iwallDirection = value; }
        }
        double dbwallTemperatureExcess;

        public double dbWallTemperatureExcess
        {
            get { return dbwallTemperatureExcess; }
            set { dbwallTemperatureExcess = value; }
        }
        bool rdowallRadiation;

        public bool rdoWallRadiation
        {
            get { return rdowallRadiation; }
            set { rdowallRadiation = value; }
        }

        int iwallType = -1;
        #endregion
        
        // Tính tổng dòng nhiệt do tường tỏa ra
        public double CalculateWallHeat(double insideTemp)
        {
            return dbWallHeatTransferCoefficient * dbwallLength * dbwallWidth*((dbwallOutsideExposure - insideTemp) + dbwallTemperatureExcess);
        }

        /// <summary>
        /// method to copy wall object to a new object
        /// </summary>
        /// <returns>a new object is wall object type</returns>
        public object Clone()
        {
            object clone;
            try
            {
                using (MemoryStream stream = new MemoryStream())
                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize this object

                    formatter.Serialize(stream, this);

                    stream.Position = 0;

                    // Deserialize to another object

                    clone = formatter.Deserialize(stream);

                }
                return clone;
            }
            catch (Exception e)
            {
                return e;
            }

        }
    }
}
